package cn.liurong.weixin.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.liurong.com.net.HttpUtils;
import cn.liurong.com.net.HttpsUtils;

/**
 * TODO: 增加描述
 * 
 * @author Administrator
 * @date 2017年4月28日 
 * @copyright wonhigh.cn 
 */
@Controller
@RequestMapping("auth_controller")
public class AuthController {

	private static final String ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=%1$s&appid=%2$s&secret=%3$s";

	@RequestMapping("get_access_token")
	public void getAccessToken(String grant_type, String appid, String secret) throws Exception {
		System.out.println("获取access_token的请求：grant_type" + grant_type + "appid" + appid + "secret" + secret);

		String requestUrl = String.format(ACCESS_TOKEN_URL, grant_type, appid, secret);
		System.out.println("请求的url为：" + requestUrl);
		String httpsContent = HttpUtils.httpGet(requestUrl);
		System.out.println(httpsContent);
	}

	public static void main(String[] args) {
		String requestUrl = String.format(ACCESS_TOKEN_URL, "client_credential", "wxe885c63a784485de",
				"afb0c5d0dc3a7ffe3345fa170eca8ccb");
		System.out.println("请求的url为：" + requestUrl);
		String httpsContent = HttpsUtils.httpsGet(requestUrl);
		System.out.println(httpsContent);
	}
}
